import api from '../api'
import {
  GOT_DETAILS_DATA
} from './bookDetailsMutations'
import {
  GET_DETAILS_DATA
} from './bookDetailsActions'

const bookDetails = {
  namespaced: true,
  state: {
    info: {},
    intro: '',
    chapterDirectory: []
  },
  mutations: {
    [GOT_DETAILS_DATA] (state, data) {
      state.info = {
        id: data.id,
        firstChapterId: data.firstChapterId,
        title: data.title,
        author: data.author,
        date: data.date,
        chapter: data.chapter,
        cover: data.cover
      }
      state.intro = data.intro
      state.chapterDirectory = data.chapterDirectory
    }
  },
  actions: {
    [GET_DETAILS_DATA] ({ commit }, value) {
      api.getDetailsPage(value)
        .then(data => {
          commit('gotDetailsData', data)
        })
    }
  },
  getters: {}
}

export default bookDetails
